import router from './router'
// import store from './store'
// import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie
// import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false }) // NProgress Configuration

const whiteList = ['/login', '/auth-redirect', '/retrieve-pass', '/shop-list'] // no redirect whitelist

router.beforeEach(async(to, from, next) => {
  const hasToken = getToken()
  if (whiteList.indexOf(to.path) !== -1) {
    document.title = to.meta.title
  } else {
    document.title = `${to.meta.title} ${localStorage.getItem('company')}`
  }
  if (hasToken || whiteList.indexOf(to.path) !== -1) {
    next()
  } else {
    next('/login')
    // next(`/login?redirect=${to.path}`)
  }
})

router.afterEach(() => {
  // finish progress bar
  NProgress.done()
})
